package org.glutenberg;

import com.sun.lwuit.Command;
import com.sun.lwuit.Component;
import com.sun.lwuit.Form;
import com.sun.lwuit.TextArea;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;

public class About extends Form implements ActionListener {

	private Form previous;

	private Handbook hb;
	private Command exit;
	private Command previousCommand;
	
	private static String ABOUT_TITLE = "Informazioni";
	
	public About(Handbook hb){
		this.setTitleComponent(Results.getTitle(ABOUT_TITLE));
		this.hb = hb;
		this.exit = new Command("Esci");
		this.previousCommand = new Command("Indietro");
		this.addCommand(this.exit);
		this.addCommand(this.previousCommand);
		this.addCommandListener(this);
		this.addComponent(this.getAbout());
	}

	private Component getAbout() {
		String about = "Sviluppato da Emanuele Sabellico (emasab@gmail.com). Distruito con licenza GPL versione 2. Un ringraziamento particolare all'Associazione Italiana Celiachia per il Prontuario degli Alimenti senza Glutine. Dedicato ad Emilia.";
		TextArea ret = new TextArea();
		ret.setEditable(false);
		ret.setText(about);
		return ret;
	}
	
	public void actionPerformed(ActionEvent ev) {
		Command c = ev.getCommand();
		if(c==this.exit){
			this.hb.quit();
		} else if(c==this.previousCommand && this.previous!=null){
			this.previous.show();
		}		
	}
	
	public static Command getAboutCommand(){
		return new Command(ABOUT_TITLE);
	}
	
	public Form getPrevious() {
		return previous;
	}

	public void setPrevious(Form previous) {
		this.previous = previous;
	}
}
